package demo.plugin;

import demo.StudentMapper;
import java.io.IOException;
import java.io.Reader;
import java.util.Date;
import java.util.HashMap;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import pojo.Student;

public class MybatisSelectKeyPlugin {
    public static void main(String[] args) {

        String resource = "mybatis-config-selectkey.xml";
        Reader reader;
        try {
            reader = Resources.getResourceAsReader(resource);
            SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
            SqlSession sqlSession = sqlSessionFactory.openSession();

            try {
                StudentMapper studentMapper = sqlSession.getMapper(StudentMapper.class);
                Student student = new Student("123", "小红", "男", new Date(), "95034");

                HashMap<String, Object> mapParam = new HashMap<>();
                mapParam.put("sno", "123");
                mapParam.put("sname", "小红");
                mapParam.put("ssex", "男");
                mapParam.put("sbirthday", new Date());
                mapParam.put("clazz", "95034");
//                mapParam.put("id", "");

                studentMapper.selectFullStudent("nan");
                System.out.println(mapParam.get("id"));
                sqlSession.commit();
            } finally {
                sqlSession.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}